#pragma once

/*
#define LG_RECD( prm1, prm2) #ifdef _DEBUG \
	lg_Recd( prm1, prm2); #endif
*/

#include "filer.h"

class Logger 
{
private:

	CString m_fname;
	CString m_path;
	Filer	mfiler;
	bool	m_fopen;

	CCriticalSection mcriticals;
	CTime	mt;
	CString mcst;
	int		md;

public:
	Logger() 
	{
		TRACE(_T("=== logger create\n"));
		m_fname = TEXT("logger.txt");
		m_path = TEXT("");
		m_fopen = false;
		md=1;
	}
	~Logger() 
	{ 
		rec( _T("logger destory"));
	}
	int init()
	{
		if( mfiler.isOpen())
			mfiler.Close();
		CString fn = m_path + m_fname;
		mfiler.Open( fn, 3 );

		rec(TEXT("logger has inited."));

		return 1;
	}

	inline void rec(CString s)
	{
		TRACE(_T("=== %s\n"), s);

		/*
		md = 0;
		mcriticals.Lock();

		mt = CTime::GetCurrentTime();
		mcst.Format( TEXT("%02d:%02d:%02d "), mt.GetHour(), mt.GetMinute(), mt.GetSecond());

		mfiler.writeLine(mcst + s);
		mfiler.mfile.Flush();

		mcriticals.Unlock();
		*/
	}
};
extern Logger glogger;
inline void lg_tcnozero( CString str, int d ) // only for debuf;
{
	if ( d )
	{
		TRACE(_T("--- %s"), str);
		TRACE(_T(" %d\n"), d);
	}
}
inline void lg_Rec(CString s)
{
	glogger.rec(s);
}
inline void lg_Rec( CString str, int d)
{
	CString s;
	s.Format(_T("%s %d"), str, d);
	glogger.rec(str);
}
inline void lg_nozero(CString s, int d)
{
	if ( d )
	{
		lg_Rec(s,d);
	}
}
